package com.yw.smartcityforjava.api;


import android.util.Log;
import android.widget.Toast;

import com.yw.smartcityforjava.App;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public abstract class ICallback<T> implements Callback<T> {


    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        if(response.isSuccessful()){
            Log.d("'network'", response.body().toString());
            onSuccess(response.body());
        }else{
            Log.e("network", response.body().toString());
            Toast.makeText(App.app, response.message(), Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onFailure(Call<T> call, Throwable throwable) {
        Log.e("network", throwable.toString());
        Toast.makeText(App.app, "网络异常，请检查网络...", Toast.LENGTH_LONG).show();
    }

    public abstract void onSuccess(T response);
}
